package com.xuelangyun.form.exterauth.controller;

import java.util.Arrays;
import java.util.List;

import com.xuelangyun.form.exterauth.entity.SysExterPermsApiEntity;
import com.xuelangyun.form.exterauth.service.ISysExterPermsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xuelangyun.form.common.utils.PageUtils;
import com.xuelangyun.form.common.utils.R;
import com.xuelangyun.form.common.validator.ValidatorUtils;
import com.xuelangyun.form.common.validator.group.AddGroup;
import com.xuelangyun.form.common.validator.group.UpdateGroup;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

/**
 * 三方应用调用权限
 *
 * @author weiqing.hk
 * 
 * @date 2024-05-25 14:06:47
 */
@RestController
@RequestMapping("exter/perms")
@Api(value = "三方应用调用权限API", tags = { "三方应用调用权限API-通用" })
public class SysExterApiPermsController {

	@Autowired
	private ISysExterPermsService sysExterPermsService;

	/**
	 * 列表
	 */
	@GetMapping("/list")
	@RequiresPermissions("exter:perms:list")
	@ApiOperation("三方应用调用权限列表-分页")
	@ApiResponse(code = 0, message = "查询成功", response = SysExterPermsApiEntity.class)
	public R<PageUtils> listPage(SysExterPermsApiEntity SysExterPerms, PageUtils page) {
		PageUtils pageData = sysExterPermsService.queryPage(SysExterPerms, page);
		return R.ok(PageUtils.class).setData(pageData);
	}
	
	/**
	 * 列表
	 */
	@SuppressWarnings("rawtypes")
	@GetMapping("/all")
	@RequiresPermissions("exter:perms:list")
	@ApiOperation("三方应用调用权限列表-全部")
	@ApiResponse(code = 0, message = "查询成功", response = SysExterPermsApiEntity.class)
	public R<List> listAllData() {
		List<SysExterPermsApiEntity> all = sysExterPermsService.list();
		return R.ok(List.class).setData(all);
	}

	/**
	 * 信息
	 */
	@GetMapping("/info/{id}")
	@RequiresPermissions("exter:perms:info")
	@ApiOperation("根据ID获取三方应用调用权限信息")
	@ApiResponse(code = 0, message = "查询成功", response = SysExterPermsApiEntity.class)
	public R<SysExterPermsApiEntity> infoById(@PathVariable("id") String id) {
		SysExterPermsApiEntity sysExterPerms = sysExterPermsService.getById(id);
		return R.ok(SysExterPermsApiEntity.class).setData(sysExterPerms);
	}

	/**
	 * 保存
	 */
	@PostMapping("/save")
	@RequiresPermissions("exter:perms:save")
	@ApiOperation("保存$三方应用调用权限信息")
	public R<Object> saveExterPerm(@RequestBody SysExterPermsApiEntity sysExterPerms) {
		ValidatorUtils.validateEntity(sysExterPerms, AddGroup.class);
		sysExterPermsService.save(sysExterPerms);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@RequiresPermissions("exter:perms:update")
	@ApiOperation("修改三方应用调用权限信息")
	public R<Object> updatePerms(@RequestBody SysExterPermsApiEntity sysExterPerms) {
		ValidatorUtils.validateEntity(sysExterPerms, UpdateGroup.class);
		sysExterPermsService.updateById(sysExterPerms);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping("/delete")
	@RequiresPermissions("exter:perms:delete")
	@ApiOperation("删除三方应用调用权限信息")
	public R<Object> deleteByIds(@RequestBody String[] ids) {
		sysExterPermsService.removeByIds(Arrays.asList(ids));
		return R.ok();
	}

}
